﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ActionSystem.Core;
namespace ActionSystem.Core.HitLogic
{
    /// <summary>
    /// 受击处理,包括状态处理，伤害计算
    /// </summary>
    public class BaseHitProcessAbility
    {
        BaseStateMachine _stateMachine;
        HitConfig config;
        public BaseHitMessageProcessor hitProcessor;
        public List<HitMessage> hits;
        public BaseStateMachine StateMachine => _stateMachine;
        public BaseHitProcessAbility(BaseStateMachine baseStateMachine)
        {
            _stateMachine = baseStateMachine;
            config = (baseStateMachine as IHitReactionConifg)?.GetHitConfig();
        }
        public virtual void OnHitBoxSetUp()
        {
            //执行当前状态的逻辑
            var currentState = _stateMachine.CurrentState;
            if (currentState == null)
            {
                return;
            }
            foreach (var action in currentState.GetActions())
            {
                if (action.IsExcuting)
                    (action.Handler as IHitBoxActionHandler)?.BoxSetUp(action);
            }

            //判断是否需要执行下一个状态
            var nextState = _stateMachine.NextState;
            if (nextState == null)
            {
                return;
            }
            
            foreach (var action in nextState.GetActions())
            {
                if (action.IsExcuting)
                    (action.Handler as IHitBoxActionHandler)?.BoxSetUp(action);
            }
        }
        public virtual void OnHitDetect()
        {
            //执行当前状态的逻辑
            var currentState = _stateMachine.CurrentState;
            if (currentState == null)
            {
                return;
            }
            foreach (var action in currentState.GetActions())
            {
                if (action.IsExcuting)
                    (action.Handler as IHitBoxActionHandler)?.HitDetect(action);
            }

            //判断是否需要执行下一个状态
            var nextState = _stateMachine.NextState;
            if (nextState == null)
            {
                return;
            }

            foreach (var action in nextState.GetActions())
            {
                if (action.IsExcuting)
                    (action.Handler as IHitBoxActionHandler)?.HitDetect(action);
            }
        }
        public void HitProcess()
        {

        }
    }
}

